﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

using System.Text;
using Microsoft.ApplicationBlocks.Data;
using Module.Core.EntitiesInfo;
using Module.EntitiesInfo;

namespace Module.DataAccess
{
  public  class AdvertisementPositionsDB
    {
      #region ConnectionString
        private string _connectionString;
        public string ConnectionString
        {
            get { return _connectionString; }
            set { _connectionString = value; }
        }
        public AdvertisementPositionsDB()
        {
            ConnectionString = ConfigurationManager.ConnectionStrings["localsql"].ToString();
        }
        #endregion
        #region Methods
        public virtual int Insert(AdvertisementPositionsInfo advertisementPositionsInfo)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@Title", advertisementPositionsInfo.Title),
				new SqlParameter("@Description", advertisementPositionsInfo.Description),
				new SqlParameter("@ShowMode", advertisementPositionsInfo.ShowMode),
				new SqlParameter("@RepeatLayout", advertisementPositionsInfo.RepeatLayout),
				new SqlParameter("@RepeatColumns", advertisementPositionsInfo.RepeatColumns),
				new SqlParameter("@RepeatDirection", advertisementPositionsInfo.RepeatDirection),
				new SqlParameter("@CreatedBy", advertisementPositionsInfo.CreatedBy),
				new SqlParameter("@CreatedOn", advertisementPositionsInfo.CreatedOn),
				new SqlParameter("@Width", advertisementPositionsInfo.Width),
                new SqlParameter("@Height", advertisementPositionsInfo.Height),
                new SqlParameter("@TimeDelay", advertisementPositionsInfo.TimeDelay),
                new SqlParameter("@Priority", advertisementPositionsInfo.Priority),
                new SqlParameter("@Lang", advertisementPositionsInfo.Lang),
                new SqlParameter("@GroupPostion", advertisementPositionsInfo.GroupPostion)

			};

            return (int)SqlHelper.ExecuteScalar(ConnectionString, CommandType.StoredProcedure, "Advertisement_Positions_Insert", parameters);
        }

        public virtual void Update(AdvertisementPositionsInfo advertisementPositionsInfo)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@Title", advertisementPositionsInfo.Title),
				new SqlParameter("@Description", advertisementPositionsInfo.Description),
				new SqlParameter("@ShowMode", advertisementPositionsInfo.ShowMode),
				new SqlParameter("@RepeatLayout", advertisementPositionsInfo.RepeatLayout),
				new SqlParameter("@RepeatColumns", advertisementPositionsInfo.RepeatColumns),
				new SqlParameter("@RepeatDirection", advertisementPositionsInfo.RepeatDirection),
				new SqlParameter("@CreatedBy", advertisementPositionsInfo.CreatedBy),
				new SqlParameter("@CreatedOn", advertisementPositionsInfo.CreatedOn),
				new SqlParameter("@Width", advertisementPositionsInfo.Width),
                new SqlParameter("@Height", advertisementPositionsInfo.Height),
                new SqlParameter("@TimeDelay", advertisementPositionsInfo.TimeDelay),
                new SqlParameter("@Priority", advertisementPositionsInfo.Priority),
                new SqlParameter("@Lang", advertisementPositionsInfo.Lang),
                new SqlParameter("@GroupPostion", advertisementPositionsInfo.GroupPostion)
			};

            SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure, "Advertisement_Positions_Update", parameters);
        }

        public virtual void Delete(int positionID)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@PositionID", positionID)
			};

            SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure, "Advertisement_Positions_Delete", parameters);
        }

        public IDataReader Select(int? type, string para_1, string para_2)
        {
            try
            {
                return SqlHelper.ExecuteReader(ConnectionString, "Advertisement_Positions_Select", type, para_1, para_2);
            }
            catch (Exception)
            {

                throw;
            }
        }
        public IDataReader Select(int? type, string para_1)
        {
            try
            {
                return SqlHelper.ExecuteReader(ConnectionString, "Advertisement_Positions_Select", type, para_1);
            }
            catch (Exception)
            {

                throw;
            }
        }
        public IDataReader Select(int? type)
        {
            try
            {
                return SqlHelper.ExecuteReader(ConnectionString, "Advertisement_Positions_Select", type);
            }
            catch (Exception)
            {

                throw;
            }
        }
        public DataTable SelectTbl(int? type, string para_1, string para_2)
        {
            try
            {
                return SqlHelper.ExecuteDataset(ConnectionString, "Advertisement_Positions_Select", type, para_1, para_2).Tables[0];
            }
            catch (Exception)
            {

                throw;
            }
        }
        public DataTable SelectTbl(int? type, string para_1)
        {
            try
            {
                return SqlHelper.ExecuteDataset(ConnectionString, "Advertisement_Positions_Select", type, para_1).Tables[0];
            }
            catch (Exception)
            {

                throw;
            }
        }
        public DataTable SelectTbl(int? type)
        {
            try
            {
                return SqlHelper.ExecuteDataset(ConnectionString, "Advertisement_Positions_Select", type).Tables[0];
            }
            catch (Exception)
            {

                throw;
            }
        }

       
      
        public virtual int GetCount(string keysearch, DateTime starDatetime, DateTime endDatetime, int beginRow, int endRow)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{                          
               new SqlParameter("@keysearch", keysearch),  
               new SqlParameter("@starDatetime", starDatetime),
               new SqlParameter("@endDatetime", endDatetime),
               new SqlParameter("@IsTotalRow", 1)
			};

            return (int)SqlHelper.ExecuteScalar(ConnectionString, CommandType.StoredProcedure, "Advertisement_Positions_Search", parameters);
        }

        /// <summary>
        /// Selects all records from the Advertisement_Positions table.
        /// </summary>
        public CHRTList<AdvertisementPositionsInfo> SelectAll()
        {
            using (SqlDataReader dataReader = SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure, "Advertisement_Positions_SelectAll"))
            {
                CHRTList<AdvertisementPositionsInfo> advertisementPositionsInfoList = new CHRTList<AdvertisementPositionsInfo>();
                while (dataReader.Read())
                {
                    AdvertisementPositionsInfo advertisementPositionsInfo =new AdvertisementPositionsInfo();
                    advertisementPositionsInfoList.Add(advertisementPositionsInfo);
                }

                return advertisementPositionsInfoList;
            }
        }
       
        public virtual DataTable Search(string keysearch,DateTime starDatetime, DateTime endDatetime, int beginRow, int endRow, string orderByColumn)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{                
                new SqlParameter("@Keysearch", keysearch),  
                new SqlParameter("@StarDatetime", starDatetime),
                new SqlParameter("@EndDatetime", endDatetime),               
                new SqlParameter("@BeginRow", beginRow),
                new SqlParameter("@EndRow", endRow),
                new SqlParameter("@OrderByColumn", orderByColumn),
				new SqlParameter("@IsTotalRow", 0)
			};

            return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure, "Advertisement_Positions_Search", parameters).Tables[0];
        }
      #endregion
    }
}
